package day21;

/**
 * 工厂模式 :看后面一个 工厂类  FactoryModles
 * 1.定义接口规范
 * 2.实现接口
 * 3.定义工厂类接口
 * 4.根据不同的子类，实现工厂类接口，返回不同的实例对象
 * 5.
 * 
 * @author: yyfei  
 * @email:  yyfei123@qq.com
 */
public class FactoryModle {
	public static void main(String[] args) {
		Logins psLogins=new nameFactory().login();
		psLogins.login("yyfei1", "123456");
		
		Logins qqLogins=new QQFactory().login();
		qqLogins.login("chenjie", "123456");
	}
}

interface Logins{
	/**
	 * 检查是否能登录
	 * @author: yyfei
	 * @email:  yyfei123@qq.com
	 */
	public abstract boolean check(String name ,String password);
	public abstract void login(String name ,String password);
}

class PassWordLogin implements Logins{
	private String nameString="yyfei";
	private String passwordString="123456";
	@Override
	public boolean check(String name,String password) {
		// TODO Auto-generated method stub
		if(nameString.equals(name)) {
			if (passwordString.equals(password)) {
				return true;
			}
		}
		return false;
	}
	
	@Override
	public void login(String name ,String password) {
		// TODO Auto-generated method stub
		if (check(name, password)) {
			System.out.println("登录成功");
		}else {
			System.out.println("用户名或密码错误，请重新登录");
		}
	}
	
}

class QQLogin implements Logins{
	private String nameString="chenjie";
	private String passwoString="123456";
	@Override
	public boolean check(String name,String password) {
		// TODO Auto-generated method stub
		if (nameString.equals(name)) {
			if (passwoString.equals(password)) {
				return true;
			}
		}
		return false;
	}
	
	@Override
	public void login(String name,String password) {
		// TODO Auto-generated method stub
		if (check(name, password)) {
			System.out.println("QQ登录成功");
		}else {
			System.out.println("QQ登录失败，请重新登录");
		}
		
	}
}

interface Factory{
	Logins login();
}

class nameFactory implements Factory{
	@Override
	public Logins login() {
		// TODO Auto-generated method stub
		return new PassWordLogin();
	}
}

class QQFactory implements Factory{
	@Override
	public Logins login() {
		// TODO Auto-generated method stub
		return new QQLogin();
	}
}



